package com.gnerv.rabbitmq.agent.command.v_3_7_x;

import com.gnerv.rabbitmq.agent.command.AbstractRabbitmqctlCommand;
import com.gnerv.rabbitmq.agent.model.entity.Node;
import com.gnerv.rabbitmq.agent.tools.ExecTools;
import com.google.common.collect.Lists;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@NoArgsConstructor
public class RabbitmqctlCommand extends AbstractRabbitmqctlCommand {

    public RabbitmqctlCommand(Node node) {
        super();
        setNode(node);
    }

    public static RabbitmqctlCommand build(Node node) {
        return new RabbitmqctlCommand(node);
    }

    public ExecTools.ExecResult addUser(String username, String password) {
        List<String> addUser = Lists.newArrayList();
        addUser.add("add_user");
        addUser.add(username);
        addUser.add(password);
        return run(addUser);
    }

    public ExecTools.ExecResult deleteUser(String username) {
        List<String> deleteUser = Lists.newArrayList();
        deleteUser.add("delete_user");
        deleteUser.add(username);
        return run(deleteUser);
    }

    public ExecTools.ExecResult setUserTags(String username, String... tags) {
        List<String> setUserTags = Lists.newArrayList();
        setUserTags.add("set_user_tags");
        setUserTags.add(username);
        setUserTags.addAll(List.of(tags));
        return run(setUserTags);
    }

    public ExecTools.ExecResult clearPassword(String username) {
        List<String> clearPassword = Lists.newArrayList();
        clearPassword.add("clear_password");
        clearPassword.add(username);
        return run(clearPassword);
    }

    public ExecTools.ExecResult changePassword(String username, String password) {
        List<String> changePassword = Lists.newArrayList();
        changePassword.add("change_password");
        changePassword.add(username);
        changePassword.add(password);
        return run(changePassword);
    }

    public ExecTools.ExecResult authenticateUser(String username, String password) {
        List<String> authenticateUser = Lists.newArrayList();
        authenticateUser.add("authenticate_user");
        authenticateUser.add(username);
        authenticateUser.add(password);
        return run(authenticateUser);
    }

    public ExecTools.ExecResult setUserLimits(String name, String definition) {
        List<String> listVhosts = Lists.newArrayList();
        listVhosts.add("set_user_limits");
        listVhosts.add(name);
        listVhosts.add(definition);
        return run(listVhosts);
    }

    public ExecTools.ExecResult clearUserLimits(String name) {
        List<String> listVhosts = Lists.newArrayList();
        listVhosts.add("clear_user_limits");
        listVhosts.add(name);
        return run(listVhosts);
    }

    public ExecTools.ExecResult listUsers() {
        List<String> addUser = Lists.newArrayList();
        addUser.add("list_users");
        return run(addUser);
    }

}
